/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 05 - 23
 * Time: 20:46
 */
class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}
public class Practice {
    public boolean chkPalindrome(ListNode A) {
        /*ListNode show = A;
        ListNode fast = A;
        //1.找中间节点
        while((fast != null) && (fast.next != null)) {
            fast = fast.next.next;
            show = show.next;
        }
        //2.从中间节点开始逆序
        ListNode cur = show.next;
        while(cur != null) {
            ListNode curNext = cur.next;
            cur.next = show;
            show = cur;
            cur = curNext;
        }
        //3.判断链表是否回文
        while(show != A) {
            if(show.val != A.val) {
                return false;
            }
            if(A.next == show) {//show.val==A.val的情况下才能有这个判断，所以这个判断放在上一个if语句之后
                return true;//节点个数为偶数的回文
            }
            show = show.next;
            A = A.next;
        }
        return true;//节点个数为奇数的回文*/
        ListNode fast = A;
        ListNode show = A;
        while((fast != null) && (fast.next != null)) {
            fast = fast.next.next;
            show = show.next;
        }
        ListNode cur = show.next;
        while(cur != null) {
            ListNode curNext = cur.next;
            cur.next = show;
            show = cur;
            cur = curNext;
        }
        while(show != A) {
            if(show.val == A.val) {
                show = show.next;
                A = A.next;
                if(A.next == show){
                    return true;
                }
            }else {
                return false;
            }
        }
        return true;
    }
    public ListNode reverseList(ListNode head) {
        if(head == null) {
            return null;
        }
        ListNode cur = head.next;
        head.next = null;
        while(cur != null) {
            ListNode curNext = cur.next;
            cur.next = head;
            head = cur;
            cur = curNext;
        }
        return head;
    }
}
